package com.sk.cardeal.adapter;

import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.cardeal.R;
import com.sk.cardeal.callback.NumChangedCallback;
import com.sk.cardeal.entity.InOrderDetailEntity;

import java.util.List;

/**
 * Created by sk on 2018/3/21.
 */

public class InDetailAdapter extends BaseQuickAdapter<InOrderDetailEntity.ResultListBean,BaseViewHolder>{

    private NumChangedCallback numChangedCallback;

    public InDetailAdapter(int layoutResId, @Nullable List<InOrderDetailEntity.ResultListBean> data,NumChangedCallback numChangedCallback) {
        super(layoutResId, data);
        this.numChangedCallback = numChangedCallback;
    }

    @Override
    protected void convert(final BaseViewHolder helper, InOrderDetailEntity.ResultListBean item) {

        String qs = "";
        switch (item.getQuality()){
            case 1:
                qs = "原厂件";
                break;
            case 2:
                qs = "品牌件";
                break;
            case 3:
                qs = "改装件";
                break;
            case 4:
                qs = "自制件";
                break;
            case 5:
                qs = "修复件";
                break;
            case 6:
                qs = "拆车件";
                break;
        }

            helper.setText(R.id.parts_name,item.getPartName())
                    .setText(R.id.tv_code,"编码："+item.getOeCode())
                    .setText(R.id.tv_quality,"品质："+qs)
                    .setText(R.id.buy_num,"采购数量："+item.getNum());

        EditText edit_num = helper.getView(R.id.edit_num);
        edit_num.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(numChangedCallback!=null){
                    numChangedCallback.changeNum(helper.getAdapterPosition(),Integer.parseInt(s.toString()));
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
}
